package com.lxh.mp.controller;

import com.lxh.mp.utils.JsonUtils;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * created by lanxinghua@2dfire.com on 2020/2/21
 */
@Controller
public class PageController {
    @GetMapping(value = "/")
    public String index(HttpServletRequest request,
                        ModelMap map) {
        HttpSession session = request.getSession();
        WxMpUser user = (WxMpUser)session.getAttribute("token");
        map.put("token", JsonUtils.toJson(user));
        map.put("img", user.getHeadImgUrl());
        return "index";
    }

    @GetMapping(value = "/jssdk")
    public String jsSdk() {
        return "jssdk";
    }

    @GetMapping(value = "/error/404")
    public String error404() {
        return "error";
    }

    @GetMapping(value = "/error/500")
    public String error500() {
        return "error";
    }
}
